package com.shensi.adminCollect.controller.station;

import com.shensi.adminCollect.common.constant.UserConstants;
import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.common.utils.StringUtils;
import com.shensi.adminCollect.common.utils.poi.ExcelUtil;
import com.shensi.adminCollect.domain.station.AppUserSuper;
import com.shensi.adminCollect.service.station.IAppUserSuperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.shensi.common.core.domain.model.LoginUser;
import com.shensi.common.core.utils.SecurityUtils;
import com.shensi.common.core.domain.entity.SysUser;
/**
 * 【超级会员】Controller
 * 
 * @author qujia
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/appusersuper")
@Api(tags = "超级会员")
public class AppUserSuperController extends BaseController
{
    @Autowired
    private IAppUserSuperService appUserSuperService;

    /**
     * 查询【超级会员】列表
     */
    @GetMapping("/list")
    @ApiOperation("获取超级会员列表")
    public TableDataInfo list(AppUserSuper appUserSuper)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        if (currentUser != null) {
            SysUser sysUser = currentUser.getUser();
            if (StringUtils.equalsAny(sysUser.getUserLevel(),UserConstants.LEVEL_TWO,UserConstants.LEVEL_THREE)) {
                // 不是admin设置本油企id
                appUserSuper.setEnterpriseId(sysUser.getEnterpriseId());
            }
        }
        startPage();
        List<AppUserSuper> list = appUserSuperService.selectAppUserSuperList(appUserSuper);
        return getDataTable(list);
    }

    /**
     * 导出【超级会员】列表
     */
    @GetMapping("/export")
    public AjaxResult export(AppUserSuper appUserSuper)
    {
        List<AppUserSuper> list = appUserSuperService.selectAppUserSuperList(appUserSuper);
        ExcelUtil<AppUserSuper> util = new ExcelUtil<AppUserSuper>(AppUserSuper.class);
        return util.exportExcel(list, "super");
    }

    /**
     * 获取【超级会员】详细信息
     */
    @GetMapping(value = "/{superId}")
    @ApiOperation("获取超级会员详情")
    public AjaxResult getInfo(@PathVariable("superId") Long superId)
    {
        return AjaxResult.success(appUserSuperService.selectAppUserSuperById(superId));
    }

    /**
     * 新增【超级会员】
     */
    @ApiOperation("添加超级会员")
    @PostMapping
    public AjaxResult add(@RequestBody AppUserSuper appUserSuper)
    {
        return toAjax(appUserSuperService.insertAppUserSuper(appUserSuper));
    }

    @ApiOperation("超级会员和手机号绑定")
    @PostMapping(value = "/addphone")
    public AjaxResult addPhone(@RequestBody AppUserSuper appUserSuper)
    {
        return AjaxResult.success(appUserSuperService.insertAppUserSuperPhone(appUserSuper));
    }
    /**
     * 修改【超级会员】
     */
    @PutMapping
    public AjaxResult edit(@RequestBody AppUserSuper appUserSuper)
    {
        return toAjax(appUserSuperService.updateAppUserSuper(appUserSuper));
    }

    /**
     * 删除【超级会员】
     */
    @DeleteMapping("/{superIds}")
    public AjaxResult remove(@PathVariable Long[] superIds)
    {
        return toAjax(appUserSuperService.deleteAppUserSuperByIds(superIds));
    }
}
